package com.fzy.designpattern.observer.custom;

/**
 * 测试类
 *
 * @author 冯赵杨
 * @create 2018/9/12
 */
public class ObserverTest {

    public static void main(String[] args) {
        //创建主题(被观察者)
        SubjectImpl magazine = new SubjectImpl();
        //创建三个不同的观察者
        ObserverImpl a = new ObserverImpl("A");
        ObserverImpl b = new ObserverImpl("B");
        ObserverImpl c = new ObserverImpl("C");
        //将观察者注册到主题中
        magazine.addObserver(a);
        magazine.addObserver(b);
        magazine.addObserver(c);

        //更新主题的数据，当数据更新后，会自动通知所有已注册的观察者
        magazine.publish();
    }
}
